local joy__yongdi = fk.CreateSkill {

  name = "joy__yongdi",

  tags = { Skill.Limited, },

}



joy__yongdi:addEffect("active", {
  name = "joy__yongdi",
  anim_type = "support",
  card_num = 0,
  target_num = 1,
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(joy__yongdi.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    if table.every(room.alive_players, function(p) return p.hp >= target.hp end) and target:isWounded() then
      room:recover({
        who = target,
        num = 1,
        recoverBy = player,
        skillName = joy__yongdi.name
      })
    end
    if table.every(room.alive_players, function(p) return p.maxHp >= target.maxHp end) then
      room:changeMaxHp(target, 1)
    end
    if table.every(room.alive_players, function(p) return p:getHandcardNum() >= target:getHandcardNum() end) then
      target:drawCards(math.min(target.maxHp, 5), joy__yongdi.name)
    end
   end
})

return joy__yongdi